package com.hongyi.common.mongoDB.utils;

import com.hongyi.common.framework.constant.HttpStatus;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 */
@Data
public class PageHelper<T> implements Serializable {

    private static final String MONGO_RESULT = "查询成功";

    // 当前页数
    private long currentPage;
    // 总记录数
    private long total;
    // 页大小
    private long pageSize;
    // 总页数
    private int totalPage;
    // 数据列表
    private List<T> rows;
    //消息状态码
    private int code;
    //消息内容
    private String msg;

    public PageHelper(long pageNum, long pageSize, long total, List<T> list) {
        this.currentPage = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.rows = list;
        this.totalPage = (int) Math.ceil((double) total / pageSize);
        this.code = HttpStatus.SUCCESS;
        this.msg= MONGO_RESULT;
    }

    public PageHelper(long pageNum, long pageSize, List<T> list) {
        this.currentPage = pageNum;
        this.pageSize = pageSize;
        this.rows = list;
        this.code = HttpStatus.SUCCESS;
        this.msg= MONGO_RESULT;
    }
}

